package com.jbit.userserver.controller;


import com.jbit.common.ResponseEntity;
import com.jbit.common.ResponseUtils;
import com.jbit.userserver.model.entity.Tenant;
import com.jbit.userserver.model.entity.User;
import com.jbit.userserver.service.TenantService;
import com.jbit.userserver.service.UserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author jobob
 * @since 2023-12-18
 */
@RestController
@RequestMapping("/user")
public class JshUserController {
    @Resource
    private UserService userService;
    @Resource
    private TenantService tenantService;
    @PostMapping("/login")
    public ResponseEntity<Map<String,Object>> login(@RequestBody User user){
        Map<String,Object> map = userService.login(user.getLoginName(),user.getPassword());
        return ResponseUtils.sendSuccess(map);
    }
    @GetMapping("/infoWithTenant")
    public ResponseEntity<Tenant> infoWithTenant(HttpServletRequest request) {
        Tenant tenant = tenantService.getTenantByToken(request);
        return ResponseUtils.sendSuccess(tenant);
    }
}
